package com.example.service.product.impl;

import com.example.dao.product.ProductDao;
import com.example.dao.product.ProductLogDao;
import com.example.pojo.Product;
import com.example.pojo.ProductLog;
import com.example.service.product.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductDao dao;
    @Autowired
    private ProductLogDao productLogDao;

    //根据商品分类ID查询
    @Override
    public List<Product> getProduct(Integer categroyId) {
        return dao.getProduct(categroyId);
    }

    private ProductLog productLog = new ProductLog();

    //修改商品
    @Override
    public int upProduct(Product product) {
        dao.upProduct(product);
        productLog.setType(3);
        productLog.setOperationTime(new Date());
        productLog.setProductID(product.getProducctId());
        productLog.setUserID(1);
        return productLogDao.addProductLog(productLog);
    }

    //删除商品
    @Override
    public void delProduct(Integer producctId) {
        dao.delProduct(producctId);
        productLog.setType(2);
        productLog.setOperationTime(new Date());
        productLog.setProductID(producctId);
        productLog.setUserID(1);
        productLogDao.addProductLog(productLog);

    }

    //添加商品
    @Override
    public int addProduct(Product product) {
        dao.addProduct(product);
        System.out.println(product);
        System.out.println(product.getProducctId());
        productLog.setType(1);
        productLog.setOperationTime(new Date());
        productLog.setProductID(product.getProducctId());
        productLog.setUserID(1);
        productLogDao.addProductLog(productLog);
        int i = dao.seleMaxId();
        int a = i+10000;
        return dao.updateProductCoud(i,a);
    }

    //修改状态
    @Override
    public int upproductSate(Integer productId,Integer productSate) {
        return dao.upproductSate(productId,productSate);
    }

    @Override
    public List<Product> getproductSate(Integer productSate) {

        return dao.getproductSate(productSate);
    }

    //根据商品名称/商品编号查询
    @Override
    public List<Product> getProductAll(String productName) {

        return dao.getProductAll(productName);
    }

    //根据商品分类查询
    @Override
    public List<Product> getCategroyId(Integer categroyId) {
        return dao.getCategroyId(categroyId);
    }

    @Override
    public void addProductExcel(List<Product> product) {
        dao.addProductExcel(product);
    }

    @Override
    public List<Product> getDaochu() {
        return dao.getDaochu();
    }

    //高级检索
    @Override
    public List<Product> selectProduct(Integer productCode,String productName,Integer currentpriceProduct,Integer hits) {
        return dao.selectProduct(productCode,productName,currentpriceProduct,hits);
    }


}
